//
// Created by 高森森 on 2022/9/21.
//

#ifndef LEETCODE_SOLUTION_4_H
#define LEETCODE_SOLUTION_4_H
#include<bits/stdc++.h>
using namespace std;

class solution_4 {
public:
    int maximumProduct(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int result=0;
        int n=nums.size();
        if(*(nums.end()-1)>=0&&*nums.begin()>=0){
            result=nums[n-1]*nums[n-2]*nums[n-3];
        }else if(*nums.begin()<0&&*(nums.end()-1)<0){
            result=nums[n-1]*nums[n-2]*nums[n-3];
        }else{
            int a=nums[0]*nums[1]*nums[n-1];
            int b=nums[n-1]*nums[n-2]*nums[n-3];
            result=a>b?a:b;
        }
        return result;
    }
};


#endif //LEETCODE_SOLUTION_4_H
